/*
 * Copyright (c) 2023 fred
 * Licensed under the Apache License,Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

import { Doctype } from './token/Doctype';
import { TokenCharacter } from './token/TokenCharacter';
import { TokenComment } from './token/TokenComment';
import { TokenEndTag } from './token/TokenEndTag';
import { TokenStartTag } from './token/TokenStartTag';
import { TokenType } from './TokenType';
export abstract class Token {
  protected readonly nullChar: string = '\u0000';
  protected readonly replacementChar: string = '\uFFFD';
  public type: TokenType;
  static readonly Unset = -1;
  private _startPos: number
  private _endPos = Token.Unset

  abstract tokenType(): string

  /**
   * Reset the data represent by this token, for reuse. Prevents the need to create transfer objects for every
   * piece of data, which immediately get GCed.
   */
  reset(): Token {
    this._startPos = Token.Unset
    this._endPos = Token.Unset
    return this
  }

  getStartPos(): number {
    return this._startPos
  }

  setStartPos(pos: number) {
    this._startPos = pos
  }

  getEndPos(): number {
    return this._endPos
  }

  setEndPos(pos: number) {
    this._endPos = pos
  }

  isDoctype(): boolean {
    return this.type == TokenType.Doctype
  }

  asDoctype(): Doctype | null {
    return null
  }

  isStartTag(): boolean {
    return this.type == TokenType.StartTag
  }

  asStartTag(): TokenStartTag|null {
    return null
  }

  isEndTag(): boolean {
    return this.type == TokenType.EndTag
  }

  asEndTag(): TokenEndTag|null {
    return null
  }

  isComment(): boolean {
    return this.type == TokenType.Comment
  }

  asComment(): TokenComment | null {
    return null
  }

  isCharacter(): boolean {
    return this.type == TokenType.Character
  }


  isCData(): boolean {
    return false
  }

  asCharacter():TokenCharacter | null {
    return null
  }

  isEOF(): boolean {
    return this.type == TokenType.EOF
  }

}


